package cn.jhc;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.protocol.HttpContext;

public class LoggerInterceptor implements HttpRequestInterceptor {

    @Override
    public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
        System.out.println(request.getRequestLine());
        for (Header header: request.getAllHeaders()) {
            System.out.println(header);
        }
        BasicHttpEntityEnclosingRequest basicRequest = (BasicHttpEntityEnclosingRequest) request;
        basicRequest.getEntity().writeTo(System.out);
        System.out.println();
    }
    
}
